home *** CD-ROM | disk | FTP | other *** search
/ Aminet 12 / Aminet 12 (1996)(GTI - Schatztruhe)[!][Jun 1996].iso / Aminet / util / misc / SplitIndexv11.lha / SplitIndexv11 / Source / SplitIndex.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-21  |  7.0 KB  |  232 lines

  1. //////////////////////////////////////////////////////////////////////////////
  2. // SplitIndex.cpp v1.2
  3. //
  4. // February 20, 1996
  5. //
  6. // ©1995,96 SynthoWare
  7. // Splits aminet index files into respective dir files
  8. //
  9. // i.e. Index-> dev, comm, ...wb
  10. //
  11. // See guide file for original author information
  12. //
  13. // Programmed By: Deryk B Robosson
  14. // E-mail:        newlook@free.org
  15. //                nur_hutsko@online.emich.edu
  16. // Snail-mail:    32609 Manistee
  17. //                Westland, MI  48186
  18. //                +1.313.990.3599
  19. // IRC: Channel #amiga as newlook
  20. //
  21. // Used: * AFrame
  22. //         - Amiga C++ OOP Programmers Enhancements
  23. //         - By Jeffry A Worth
  24. //           - e-Mail: worth@online.emich.edu
  25. //                     73410.1112@compuserve.com
  26. //         - And Deryk B Robosson
  27. //           - See above or guide for bug reports etc.
  28. //
  29. //       * CygnusEd Professional v3.6
  30. //         - From CygnusSoft Software
  31. //         - Copyright © 1987-1993 CygnusSoft Software
  32. //
  33. //////////////////////////////////////////////////////////////////////////////
  34.  
  35. //////////////////////////////////////////////////////////////////////////////
  36. // Includes
  37. #include "aframe:include/amigaapp.hpp"
  38. #include "aframe:include/window.hpp"
  39. #include "aframe:include/rastport.hpp"
  40. #include "aframe:include/rect.hpp"
  41. #include "aframe:include/button.hpp"
  42. #include "aframe:include/reqtools.hpp"
  43. #include "aframe:include/string.hpp"
  44. #include <stdlib.h>
  45. #include <stdio.h>
  46.  
  47. #define LINESIZE    81          // max size of line in index
  48. #define DIRSIZE     5           // max size of aminent directory +1 - e.g.:
  49.                                 // MODS, DIR, WB, COMM
  50. FILE *indexfile, *outfile = NULL; // input and output file pointers
  51.  
  52. char    line[LINESIZE], dirold[DIRSIZE], dirnew[DIRSIZE];
  53. AFString sourcefile, destfile, desttemp;  // set aside three strings to use
  54. char    *q;
  55. int     ok=TRUE;
  56.  
  57. //////////////////////////////////////////////////////////////////////////////
  58. // ControlWindow Class Definition
  59.  
  60. class ControlWindow : public AFWindow
  61.  
  62. {
  63. public:
  64.   virtual void OnCreate();
  65.   virtual void OnCloseWindow(LPIntuiMessage imess);
  66.   virtual void OnGadgetUp(LPIntuiMessage imess);
  67.   virtual void DestroyWindow();
  68.   virtual ULONG WindowFlags();
  69.  
  70.   AFReqTools rt;
  71.   AFButton SourceBut, DestBut, GoBut;
  72. };
  73.  
  74. //////////////////////////////////////////////////////////////////////////////
  75. // ControlWindow Implementation routines
  76.  
  77. void ControlWindow::OnCloseWindow(LPIntuiMessage imess)
  78. {
  79.   AFWindow::DestroyWindow();
  80. }
  81.  
  82. void ControlWindow::DestroyWindow()     // cleanup
  83. {
  84.     if(indexfile) {
  85.         fclose(indexfile);
  86.         indexfile=NULL;
  87.     }
  88.     if(outfile)
  89.         outfile=NULL;
  90. }
  91.  
  92. void ControlWindow::OnCreate()          // things to do when window created
  93. {
  94.     rt.RTCreate();  // create reqtools object
  95. }
  96.  
  97. void ControlWindow::OnGadgetUp(LPIntuiMessage imess)  // handle gadget up messages
  98. {
  99.   AFReqTools rt;
  100.   static ULONG sourcetags[]={ RTEZ_ReqTitle,(ULONG)"Source",TAG_END };
  101.   static ULONG desttags[]={ RTEZ_ReqTitle,(ULONG)"Destination",TAG_END };
  102.   static int i;
  103.  
  104.   switch(((struct Gadget*)imess->IAddress)->GadgetID) {
  105.  
  106.   case 100:     // Get source filename
  107.     if(!(rt.RTFileRequest()))
  108.         rt.RTEZRequestA((char *)"You didn't select a SOURCE file!",(char *)"Ok",NULL,sourcetags);
  109.     else
  110.         if(rt.m_filerequester->Dir != NULL) {
  111.             sourcefile = rt.m_filerequester->Dir;
  112.  
  113.             if(sourcefile[sourcefile.length()-1]==':') // are we a device?
  114.                 sourcefile += rt.filename;
  115.             else {                                     // or device/directory?
  116.                 sourcefile += "/";
  117.                 sourcefile += rt.filename;
  118.             }
  119.         } else sourcefile=(AFString)rt.filename;
  120.  
  121.     break;
  122.  
  123.   case 101:     // Get destination directory
  124.     if(!(rt.RTFileRequest()))
  125.         rt.RTEZRequestA((char *)"You didn't select a DESTINATION directory!",(char *)"Ok",NULL,desttags);
  126.     else
  127.         if(rt.m_filerequester->Dir != NULL) {
  128.             desttemp = rt.m_filerequester->Dir;
  129.             if(desttemp[desttemp.length()-1]==(char)':'){ // are we a device?
  130.                 //do nothing
  131.                 desttemp += rt.filename;
  132.             } else {                                       // or a device/directory?
  133.                 desttemp += "/";
  134.                 desttemp += rt.filename;
  135.             }
  136.         } else desttemp=(AFString)rt.filename;
  137.  
  138.     break;
  139.  
  140.   case 102:     // Create subindex files
  141.     if (!(indexfile=fopen((const char *)sourcefile.data(),"r"))) {
  142.         rt.RTEZRequest("Unable to open SOURCEFILE","Ok");
  143.         sourcefile=NULL;
  144.         break;
  145.     }
  146.  
  147.     fgets (line,LINESIZE,indexfile); // move file pointer past index header info
  148.  
  149.     while (*line=='|')
  150.         fgets (line,LINESIZE,indexfile);
  151.  
  152.     // Now pointing to start of aminet listings
  153.  
  154.     while (ok) {  // loop through index line by line
  155.         fgets (line,LINESIZE,indexfile);
  156.  
  157.         if (! feof(indexfile)) { // end of file??
  158.             // copy DIR type (comm,dir,wb etc...) to dirnew
  159.  
  160.             // NB: the check for the space is there because I discovered an
  161.             // INDEX file with an entry under "gfx" only, not "gfx/xxx", which
  162.             // caused an error... The check stops this occurance from crashing
  163.             // the machine, or producing another list.gfx file due to the anomoly
  164.             for (i=0, q=&line[19]; !(*q=='/' || *q==' ') ; q++, i++)
  165.                 dirnew[i] = *q;
  166.  
  167.             dirnew[i]=NULL;                 // add NULL-terminator
  168.  
  169.             if (strcmp((const char *)dirnew,dirold) != 0) { // different DIR type?
  170.                 // close old output file
  171.                 if(outfile) fclose(outfile);
  172.  
  173.                 destfile = desttemp;
  174.                 destfile += "_";
  175.                 destfile += dirnew;
  176.  
  177.                 // open new file
  178.                 if(!(outfile=fopen((const char *)destfile.data(),"w"))) {
  179.                     // can't open output file - cleanup
  180.                 
  181.                     rt.RTEZRequestA("ERROR! Unable to open DESTINATION file",
  182.                                "Ok",NULL,desttags);
  183.  
  184.                     fclose(indexfile);
  185.                     break;
  186.                 }
  187.                 strcpy(dirold,dirnew);      // make dirold = dirnew
  188.             }
  189.             fprintf(outfile,"%s",line);     // write item to outfile
  190.         } else ok = FALSE;                  // quit while loop
  191.     }
  192.  
  193.     rt.RTEZRequest("All Done!","Ok");
  194.     break;
  195.  
  196.   default:  // message must have not been ours
  197.     AFWindow::OnGadgetUp(imess);
  198.     break;
  199.   }
  200. }
  201.  
  202. ULONG ControlWindow::WindowFlags()          // set our window flags
  203. {
  204.   return (AFWindow::WindowFlags() | WFLG_GIMMEZEROZERO);
  205. }
  206.  
  207. //////////////////////////////////////////////////////////////////////////////
  208. // MAIN
  209.  
  210. void main()
  211. {
  212.   AFAmigaApp theApp;
  213.   AFRect rect(10,10,410,160);
  214.   ControlWindow win;
  215.  
  216.   rect.SetRect(10,10,190,62);
  217.   win.Create(&theApp,&rect,"SPlitIndex");
  218.  
  219.   rect.SetRect(2,2,52,35);
  220.   win.SourceBut.Create("Source",&win,&rect,100);
  221.  
  222.   rect.SetRect(54,2,104,35);
  223.   win.DestBut.Create("Dest",&win,&rect,101);
  224.  
  225.   rect.SetRect(106,2,156,35);
  226.   win.GoBut.Create("GO!",&win,&rect,102);
  227.  
  228.   win.RefreshGadgets();
  229.  
  230.   theApp.RunApp();
  231. }
  232.